<template>
  <el-dialog
    :title="form.id ? '编辑权限' : '增加权限'"
    :visible="digshow"
    @close="closedig"
    v-cloak
  >
    <el-form :model="form" ref="myfrom">
      <el-form-item label="权限名称" :label-width="formLabelWidth">
        <el-input v-model="form.name" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="权限标识" :label-width="formLabelWidth">
        <el-input v-model="form.code" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="权限描述" :label-width="formLabelWidth">
        <el-input v-model="form.description" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="企业可见" :label-width="formLabelWidth">
        <el-switch
          active-color="#13ce66"
          inactive-color="#ff4949"
          v-model="form.enVisible"
          active-value="1"
          inactive-value="0"
          active-text="可见"
          inactive-text="不可见"
        >
        </el-switch>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="closedig">取 消</el-button>
      <el-button type="primary" @click="subclick">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {
  getxqpermission,
  exitpermission,
  addpermission,
} from "@/api/permission";
export default {
  props: ["digshow"],
  data() {
    return {
      form: {
        name: "",
        code: "",
        description: "",
        enVisible: "",
      },
      formLabelWidth: "120px",
      permissionid: "",
    };
  },
  methods: {
    closedig() {
      this.$emit("closedig", false);
      this.form = { name: "", code: "", description: "", enVisible: "" };
    },
    async getinfoid(id) {
      this.permissionid = id;
      let res = await getxqpermission(id);
      this.form = res;
    },
    setprop(type, pid) {
      this.form.type = type;
      this.form.pid = pid;
    },
    async subclick() {
      if (this.form.id) {
        await exitpermission({ ...this.form });
        this.$emit("updatepermission");
        this.$emit("closedig", false);
        this.$message.success("修改成功！");
      } else {
        await addpermission({ ...this.form });
        this.$emit("updatepermission");
        this.$emit("closedig", false);
        this.$message.success("添加成功！");
      }
    },
  },
};
</script>

<style lang='scss'>
[v-cloak] {
  display: none;
}
</style>